package com.znjb.myapplication;

import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by lx on 2016/6/19.
 */
public abstract class BaseFragment extends Fragment {
    protected  LoadingPage loadingPage;

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (loadingPage == null){
            loadingPage = new LoadingPage(getContext()) {
                @Override
                protected View createSuccessView() {
                    return getSuccessView();
                }

                @Override
                protected Object loadData() {
                    return requestData();
                }
            };
        }else {
            //需要拿到父类，然后移除自己,5.0之后不用
            CommonUtil.removeSelfFromParent(loadingPage);
        }
        return loadingPage;
    }

    /**
     * 获取每个子类的数据
     * @return
     */
    abstract Object requestData();

    /**
     * 获取每个子类的View
     * @return
     */
    abstract View getSuccessView() ;
}
